package com.scuvc.utils;

import com.scuvc.dao.*;
import com.scuvc.entity.CarInfo;
import com.scuvc.entity.PageBean;
import com.scuvc.entity.RecordInfo;
import com.scuvc.entity.UserInfo;
import com.scuvc.service.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class StaticUtils {
    //用户信息
    public static UserInfo user = null ;
    public static PageBean<CarInfo> pageBean = null;
    public static PageBean<RecordInfo> pageBeanR = null ;
    public static List<JLabel> refresh = null ;
    public static List<JComponent> refreshC = null;
    public static JMenuItem[][] jmiList = null;

    public static List<CarInfo> carList = null ;
    public static List<RecordInfo> recordList = null ;
    public static UserInfoDao userInfoDao = null ;
    public static UserInfoService userInfoService = null ;
    public static CarInfoDao carInfoDao = null ;
    public static CarInfoService carInfoService = null ;
    public static BrandInfoDao brandInfoDao = null ;
    public static BrandInfoService brandInfoService = null ;
    public static ModelInfoDao modelInfoDao = null ;
    public static ModelInfoService modelInfoService = null ;
    public static CategoryInfoDao categoryInfoDao = null ;
    public static CategoryInfoService categoryInfoService = null ;
    public static RecordInfoDao recordInfoDao = null ;
    public static RecordInfoService recordInfoService = null ;
    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
    //将时间字符串转换为Date类型
    public static Date parse(String dates){
        try {
            return StaticUtils.sdf.parse(dates);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null ;
    }
    //将时间类型转为字符串类型
    public static String format(Date date){
        return StaticUtils.sdf.format(date);
    }


    public static void setFoucusListener(JTextField jf) {
        FocusListener focusListener = new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {
                jf.setBackground(Color.BLACK);
                jf.setForeground(Color.WHITE);
            }
            @Override
            public void focusLost(FocusEvent e) {
                jf.setBackground(Color.WHITE);
                jf.setForeground(Color.BLACK);
            }
        };
        jf.addFocusListener(focusListener);
    }
}
